<%@ page language="java" import="java.util.*"  pageEncoding="utf-8"%>
<%@include file="common/tag.jsp"%>
<c:set var="CTX" value="${pageContext.request.contextPath}" />
<%@include file="common/indexhead.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
    
    <title>流程信息新增页</title>
    </head>

 <body>
<div class="panel panel-primary">
	<div class="panel-heading">
		<div>
			<h3 class="panel-title">流程信息新增页</h3>
		</div>
		<div class="button"
			style="float: right;margin-top: -27px;margin-right: 5px;">
			<a class="btn btn-info" href="#" onclick="javascript:window.close();"><i class="fa fa-sign-out"></i>退出</a>
		</div>
		<div class="button"
			style="float: right;margin-top: -27px;margin-right: 5px;">
			<div class="btn btn-info"   onclick="tijiao()" href=""><i class="fa fa-check"></i>保存</div>
		</div>
	</div>
	<div class="panel-body" style="height:87%">
			
			
			<form action="/flowinfo/adddo" method="post"  id="flowinfoadd"  class="form-horizontal"
			style="width:95%;margin-top: 50px;">
			<fieldset>
			<table class="table table-bordered">
				<div class="form-group">
					<label class="col-sm-2 control-label">使用模块</label>
					<div class="col-sm-4">
						<input class="form-control" id="useDb" name="useDb" type="text"/>
					</div>
					<label class="col-sm-2 control-label">模块url</label>
					<div class="col-sm-4">
						<input class="form-control" id="useDbUrl" name="useDbUrl" type="text"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">模块类别</label>
					<div class="col-sm-4">
						<input class="form-control" id="flowInfoType" name="flowInfoType" type="text"/>
					</div>
					<label class="col-sm-2 control-label">是否启用</label>
					<div class="col-sm-4">
						<select class="form-control" id="flowInfoUse" name="flowInfoUse">
            				<option value="true">是</option>
            				<option value="false">否</option>
        				</select>
					</div>
				</div>
				</table>
			</fieldset>
			<hr></hr>
<table class="table table-bordered">
  <caption style="width:90%">流程信息明细
  <p style="float:right;width:50%;text-align:right">
  <a  onclick="addTable();" class="btn btn-info">增加环节</a>
  <a  onclick="del();" class="btn btn-danger">批量删除</a>
  </p></caption>
  <thead>
    <tr>
	  <th style="width:3%"><input type='checkbox'  id='checkAll' onclick="checkAll_f()" value='New'></th>
      <th>环节编号</th>
      <th>环节名称</th>
      <th>上一环节</th>
      <th>上一环节编号</th>
      <th>下一环节</th>
      <th>下一环节编号</th>
      <th>审批人</th>
      <th>入库</th>
      <th>出库</th>
      <th>提交</th>
      <th>保存</th>
      <th>领料</th>
      <th>退回</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody id="addTable">
  </tbody>
</table>
		</form>
		<hr></hr>
		
			<style>
.table >thead> tr> th{
	text-align:center;
	vertical-align: middle;
	background-color: #DDD9D4;
	border-color:#BEC2C1;
	padding-left: 0px;
}
.table >tbody> tr> td>input{
	width:100%;
}
.table >tbody> tr> td {
	text-align:center;
	width:8%
}
</style>

	</div>
</div>
<div id="deptdialognew" style="display:none">
	<div class="zTreeDemoBackground" style="float:left">
		<ul id="treeDemo" class="ztree"></ul>
	</div>
</div>
<!-- 弹出框重写 -->
<div id="ycf-alert" class="modal">
      <div class="modal-dialog modal-sm">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
            <h5 class="modal-title"><i class="fa fa-exclamation-circle"></i> [Title]</h5>
          </div>
          <div class="modal-body small">
            <p>[Message]</p>
          </div>
          <div class="modal-footer" >
            <button type="button" class="btn btn-primary ok" data-dismiss="modal">[BtnOk]</button>
            <button type="button" class="btn btn-default cancel" data-dismiss="modal">[BtnCancel]</button>
          </div>
        </div>
      </div>
    </div>
<!-- 弹出框重写end -->
<%@include file="common/indexbottom.jsp"%>
<%-- <link rel="stylesheet" href="${pageContext.request.contextPath}/mystyle/zTreeStyle/css/demo.css" type="text/css"> --%>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/mystyle/zTreeStyle/css/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${pageContext.request.contextPath}/mystyle/zTreeStyle/js/jquery.ztree.core.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/mystyle/zTreeStyle/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript">
var row_count = 0; 
function addTable(){
	var table1 = $("#addTable");
	row_count++; 
	//var table1 = $('#table1'); 
	var firstTr = table1.find('tbody>tr:first'); 
	var row = $("<tr></tr>"); 
	var tdsc = $("<td></td>");
	var tdxh = $("<td style='width:3%'></td>"); 
	tdxh.append($("<input type='checkbox' name='count' value='New'>")); 
	row.append(tdxh); 
	
		 row.append("<td><input class='form-control'  type='text'></td>") ;
		 row.append("<td><input class='form-control'  type='text'></td>") ;
		 row.append("<td><input class='form-control'  type='text'></td>") ;
		 row.append("<td><input class='form-control'  type='text'></td>") ;
		 row.append("<td><input class='form-control'  type='text'></td>") ;
		 row.append("<td><input class='form-control'  type='text'></td>") ;
		 row.append("<td style='display:none'><input readonly=true class='form-control'  type='text'></td>") ;
		 row.append("<td><input onclick='newCheckperson(this)' readonly=true class='form-control'  type='text'></td>") ;
		 row.append("<td><select><option value='是'>是</option><option value='否'>否</option></select></td>") ;
		 row.append("<td><select><option value='是'>是</option><option value='否'>否</option></select></td>") ;
		 row.append("<td><select><option value='是'>是</option><option value='否'>否</option></select></td>") ;
		 row.append("<td><select><option value='是'>是</option><option value='否'>否</option></select></td>") ;
		 row.append("<td><select><option value='是'>是</option><option value='否'>否</option></select></td>") ;
		 row.append("<td><select><option value='是'>是</option><option value='否'>否</option></select></td>") ;
		
	var tdsc = $("<td></td>");
	tdsc.append("<input type='button' value='删除' class='btn btn-danger' onclick='delRow(this)'>") ;
	row.append(tdsc); 
	table1.append(row); 
	//$( ".mydate" ).datepicker();
}
function newCheckperson(obj){
	$("#deptdialog").dialog({
		autoOpen : false,   // 是否自动弹出窗口
		modal : true,    // 设置为模态对话框
		resizable : true,
		width : 510,   //弹出框宽度
		height : 440,   //弹出框高度
		title : "选择人员",  //弹出框标题
		position : "center",  //窗口显示的位置
		buttons:{
			'确定':function(){
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				if(treeObj.getCheckedNodes().length!=0){
					var checkId = treeObj.getCheckedNodes()[0];
					obj.value = checkId.name;
					obj.parentNode.previousSibling.firstChild.value=checkId.id;
				}else{
					alert("请选择人员！");
				}
				$(this).dialog("close");
			},
			'取消':function(){
			$(this).dialog("close");
			}
		}
	});
	//console.log(obj.value);
	var json = "";
	var setting = {
			data: {
				simpleData: {
					enable: true
				}
			},
			check :{
				radioType : "all",
				enable: true,
				chkStyle: "radio"
			}
		};
	$.ajax({
        type: "get",
        url: "util/getusernew",
        dataType: "json",
        data: "",
        success: function(data) {
        	json = data;
			var zNodes = eval(json);
			//console.log(zNodes);
	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
            alert(textStatus);
            alert(errorThrown);
        }
    });
    $("#deptdialog").dialog("open");
}
function delRow(obj){ 
	$(obj).parent().parent().remove(); 
	row_count--;
}
function del(){ 
	var checked = $("input[type='checkbox'][name='count']"); 
	$(checked).each(function(){ 
		if($(this).prop('checked')){ //注意：此处判断不能用$(this).attr("checked")==‘true'来判断。 
			$(this).parent().parent().remove(); 
		} 
	});
	row_count=$("input[type='checkbox'][name='count']").length;
	$("#checkAll").prop('checked',false);
}
function checkAll_f(){
	var checked = $("input[type='checkbox'][name='count']");
	$(checked).each(function(){ 
		if($("#checkAll").prop('checked')){
			$(this).prop('checked',true);
		}else{
			$(this).prop('checked',false);
		}
	});
}
$(function() {
//$( ".mydate" ).datepicker();

window.Modal = function() {
    var reg = new RegExp("\\[([^\\[\\]]*?)\\]", 'igm');
    var alr = $("#ycf-alert");
    var ahtml = alr.html();
    
    var _alert = function(options) {
        alr.html(ahtml); // 复原
        alr.find('.ok').removeClass('btn-success').addClass('btn-primary');
        alr.find('.cancel').hide();
        _dialog(options);

        return {
            on: function(callback) {
                if (callback && callback instanceof Function) {
                    alr.find('.ok').click(function() {
                        callback(true)
                    });
                }
            }
        };
    };

    var _confirm = function(options) {
        alr.html(ahtml); // 复原
        alr.find('.ok').removeClass('btn-primary').addClass('btn-success');
        alr.find('.cancel').show();
        _dialog(options);

        return {
            on: function(callback) {
                if (callback && callback instanceof Function) {
                    alr.find('.ok').click(function() {
                        callback(true)
                    });

                }
            }
        };
    };

    var _dialog = function(options) {
        var ops = {
            msg: "提示内容",
            title: "操作提示",
            btnok: "确定",
            btncl: "取消"
        };

        $.extend(ops, options);

        console.log(alr);

        var html = alr.html().replace(reg,
        function(node, key) {
            return {
                Title: ops.title,
                Message: ops.msg,
                BtnOk: ops.btnok,
                BtnCancel: ops.btncl
            } [key];
        });

        alr.html(html);
        alr.modal({
            width: 500,
            backdrop: 'static'
        });
    }

    return {
        alert: _alert,
        confirm: _confirm
    }

} ();
});
 
function tijiao() {
Modal.confirm({
    msg: "是否新增？"
}).on(function(e) {
	if($("#addTable tr").length==0){
		alert("流程环节不可为空!");
		return false;
	}
	var json = "{";
	for(var q=0;q<$("#addTable tr").length;q++){
		var allOutSourcingIn = $("#addTable tr")[q].children;
		json=json+"'details["+q+"].flowDetailsNumber':'"+allOutSourcingIn[1].childNodes[0].value+"',";
		json=json+"'details["+q+"].flowDetailsName':'"+allOutSourcingIn[2].childNodes[0].value+"',";
		json=json+"'details["+q+"].flowDetailsUp':'"+allOutSourcingIn[3].childNodes[0].value+"',";
		json=json+"'details["+q+"].flowDetailsUpId':'"+allOutSourcingIn[4].childNodes[0].value+"',";
		json=json+"'details["+q+"].flowDetailsDown':'"+allOutSourcingIn[5].childNodes[0].value+"',";
		json=json+"'details["+q+"].flowDetailsDownId':'"+allOutSourcingIn[6].childNodes[0].value+"',";
		json=json+"'details["+q+"].flowDetailsFzrId':'"+allOutSourcingIn[7].childNodes[0].value+"',";
		json=json+"'details["+q+"].flowDetailsFzr':'"+allOutSourcingIn[8].childNodes[0].value+"',";
		json=json+"'details["+q+"].flowDetailsOrder':'"+q+"',";
		json=json+"'details["+q+"].ruKu':'"+allOutSourcingIn[9].childNodes[0].value+"',";
		json=json+"'details["+q+"].tiJiao':'"+allOutSourcingIn[10].childNodes[0].value+"',";
		json=json+"'details["+q+"].chuKu':'"+allOutSourcingIn[11].childNodes[0].value+"',";
		json=json+"'details["+q+"].baoCun':'"+allOutSourcingIn[12].childNodes[0].value+"',";
		json=json+"'details["+q+"].lingLiao':'"+allOutSourcingIn[13].childNodes[0].value+"',";
		json=json+"'details["+q+"].tuiHui':'"+allOutSourcingIn[14].childNodes[0].value+"',";
	}
	json=json+"'useDb':'"+$("#useDb").val()+"',";
	json=json+"'flowInfoType':'"+$("#flowInfoType").val()+"',";
	json=json+"'flowInfoUse':'"+$("#flowInfoUse").val()+"',";
	json=json+"'useDbUrl':'"+$("#useDbUrl").val()+"'";
	json=json+"}";
	console.log(json);
	
	var b=eval('(' + json+ ')');
	//console.log(b);
	//console.log(eval('(' + a+ ')'));
    $.ajax({
        type: "post",
        url: yongan.URL.flowinfoAdd(),
        dataType: "json",
       //	contentType: 'application/json;charset=utf-8',
        data: b,
        success: function(data) {
            if (data['success']) {
                Modal.alert({
                    msg: data['data']['stateinfo'],
                    title: '执行结果',
                    btnok: '确定',
                    btncl: '取消'
                }).on(function(e) {
                    window.close();
                });
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
            alert(textStatus);
            alert(errorThrown);
        }
    });
});
}
</script>
  </body>
</html>